package com.kwq.email.service;


import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author kwq
 * @Date 2022/8/16
 */
@Service
@Slf4j
public class EmailService {

    private  final Logger logger = LoggerFactory.getLogger(EmailService.class);

    @Value("${spring.mail.username}")
    private String provider;

    @Resource
    private JavaMailSender sender;

    /*发送邮件的方法*/
    public void sendEmail(String acceptor, String title, String content){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(provider); //发送者
        message.setTo(acceptor); //接受者
        message.setSubject(title); //发送标题
        message.setText(content);  //发送内容
        sender.send(message);

        logger.info("TO:"+"["+acceptor+"]"+"发送成功");

    }

}


